 #!/usr/bin/python
 # -*- coding: utf-8 -*-


# Echo server program
import socket
import os

HOST = ''                 # Symbolic name meaning the local host
PORT = 50007              # Arbitrary non-privileged port

while 1:

	s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	s.bind((HOST, PORT))
	s.listen(1)
	conn, addr = s.accept()
	print 'Connected by', addr
	while 1:
	    data = conn.recv(1024)
	    if not data: break
	    conn.send(data)
	    li=data.split(',')
	    print "source", li[0], "destination", li[1], "adding"
	    os.popen("/sbin/iptables -I INPUT 1 -s %s -d %s -j ACCEPT" % (li[0], li[1]))
	    print "added"
	    print "..."
	conn.close()